﻿using System;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using AjaxControlToolkit;

[assembly: WebResource("SCS.Web.UI.WebControls.Dialogs.IFrameDialogControl.js", "text/javascript")]
[assembly: WebResource("SCS.Web.UI.WebControls.Dialogs.IFrameDialogControl.debug.js", "text/javascript")]

namespace SCS.Web.UI.WebControls.Dialogs
{
    [RequiredScript(typeof(Dialog), 1)]
    [ClientScriptResource("SCS.IFrameDialogControl", "SCS.Web.UI.WebControls.Dialogs.IFrameDialogControl.js", LoadOrder = 2)]

    public class IFrameDialog : Dialog
    {
        private HtmlGenericControl _iframe;

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

        }
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            _iframe = new HtmlGenericControl("iframe");
            _iframe.ID = this.ID + "_frame";
            _iframe.Style["border"] = "0";
            _iframe.Attributes["frameborder"] = "0";
            _iframe.Attributes["width"] = "100%";
            _iframe.Attributes["height"] = "100%";
            
            Controls.Add(_iframe);
        }
        protected override void RenderDialogContent(HtmlTextWriter writer)
        {
            base.RenderDialogContent(writer);

            _iframe.RenderControl(writer);
        }
        protected override List<object> GetAdditionalShowArguments()
        {
            List<object> list = new List<object>();
            list.Add(FrameUrl);

            return list;
        }

        public virtual void Show(string text, string caption, string frameUrl)
        {
            FrameUrl = frameUrl;

            base.Show(text, caption);
        }

        [Category("CSS Classes"), DefaultValue(""), Description(""), Bindable(true), Themeable(true)]
        [PersistenceMode(PersistenceMode.Attribute), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true)]  
        public virtual string FrameCssClass
        {
            get
            {
                return _iframe.Attributes["class"];
            }
            set
            {
                EnsureChildControls();
                _iframe.Attributes["class"] = value;
            }
        }

        [ExtenderControlProperty]
        [UrlProperty]
        [Category("Behavior"), DefaultValue(""), Description(""), Bindable(true), Themeable(false)]
        public virtual string FrameUrl
        {
            get
            {
                object o = ViewState["FrameUrl"];

                if (o != null)
                    return (string)o;

                return "";
            }
            set
            {
                ViewState["FrameUrl"] = value;
            }
        }

        [ExtenderControlProperty]
        [ClientPropertyName("loadOnInit")]
        [Category("Behavior"), DefaultValue(false), Description(""), Bindable(true), Themeable(false)]
        public virtual bool LoadOnInit
        {
            get
            {
                object o = ViewState["LoadOnInit"];

                if (o != null)
                    return (bool)o;

                return false;
            }
            set
            {
                ViewState["LoadOnInit"] = value;
            }
        }
    }
}
